The present invention relates generally to the field of computer virtual memory, and more particularly to a zero copy file transfer implementation using the virtual memory manager (VMM) of an operating system.
Copying a file from a source to a destination is a common user operation. For example, a web-based application may serve significant amounts of data such as music, video, and other data files. Even though much of the data may be static, meaning that it remains unchanged, data transfers between user address spaces cause context switches which can negatively impact overall performance, since each time a block of data crosses a user-kernel boundary it is copied to another buffer. The data transfers consume CPU cycles and memory bandwidth. Most UNIX operating systems provide a zero copy implementation which minimizes or avoids the context switches caused by multiple user spaces issuing multiple read/write calls to perform the file copy.
In one example of a zero copy implementation, memory for the copying operation can be reduced by using the memory mapped file facility of a virtual memory manager (VMM) in conjunction with the operating system file management component. While memory mapping can be used to provide access to a file by more than one user (i.e., address space), there is only one copy of the file and additional mapping techniques are required to complete a copy operation.
In another example, a file may be shared through a dummy parent segment as a result of a fork( ) system call, whereby the parent process creates a new user process (i.e., child process). The child process inherits the parent's process image (i.e., address space), but the read-only pages may be shared between the parent and child. Only the read-write pages are copied to the child. Additional operations are required to create a copy of the file.
In a further example, a file may be shared by transferring a reference to the shared memory containing the file. In this approach, the operating system structure that maps the file pages is changed to reference a new file, but the actual pages still belong to the original file.
However, there are still cases where memory usage and context switching is needed to complete the transfer of data from a source VMM page to a destination VMM page. An improved zero copy implementation using the VMM may further increase performance by reducing context switches and memory consumption, thereby freeing CPU cycles for other work.